Problem
Willem, Chtholly and Seniorious
Description
— Willem…
— What’s the matter?
— It seems that there’s something wrong with Seniorious…
— I’ll have a look…
is made by linking special talismans in particular order.
After over years, the carillon is now in bad condition, so Willem decides to examine it thoroughly.
has pieces of talisman. Willem puts them in a line, the of which is an integer .
In order to maintain it, Willem needs to perform operations.
There are four types of operations:
- : For each such that , assign to .
- : For each such that , assign to .
- : Print the smallest number in the index range , i.e. the element at the position if all the elements such that are taken and sorted into an array of non-decreasing integers. It’s guaranteed that .
- : Print the sum of the power of such that , modulo , i.e. .
Input
The only line contains four integers (,,.
The initial values and operations are generated using following pseudo code:
1 | def rnd(): |
Here is the type of the operation mentioned in the legend.
Output
For each operation of types or , output a line containing the answer.
Example
Input 1
1 | 10 10 7 9 |
Output 1
1 | 2 |
Input 2
1 | 10 10 9 9 |
Output 2
1 | 1 |
Note
In the first example, the initial array is .
The operations are:
标签:ODT
Translation
给出一个长为级别的初始数组,要求维护四种操作:
- 将中的每个数
- 将中的每个数赋为
- 询问区间中的第小值
- 询问
Solution
裸题。
用一棵set
维护若干区间,每个区间都是值相等的一段。
对于操作,将与有交集的所有区间都拿出来,如果是包含的区间,可以直接将区间值;如果是部分相交,则把区间拆成两部分(或三部分),分别赋值后删除原区间,插入新区间。
对于操作,将所有包含区间提出并删除,分成至多三段,即,其中和是与部分相交的两个区间的左端点和右端点。将左右两个区间赋值为原来的值,将中间的区间赋值为。
对于询问,将所有相交区间合起来排序再枚举判断即可。
对于询问,将所有相交区间提出来得到每个值的个数,直接统计贡献即可。
复杂度证明见lxl的题解
Code
1 |
|